package activator;

import library.service.Book;
import library.service.LibraryService;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class Activator implements BundleActivator {

	public void start(BundleContext context) throws Exception {
		ServiceReference sr = context.getServiceReference(LibraryService.class
				.getName());
		if (sr != null) {
			System.out.println("ServiceReference != null");
			LibraryService libServ = (LibraryService) context.getService(sr);
			if (libServ != null) {
				System.out.println("LibraryService != null");
				Book book = libServ.findBookByName("OSGi");
				if (book != null) {
					System.out.println("Book name: " + book.getName());
				} else {
					System.out.println("Book NOT FOUND");
				}
			} else {
				System.out.println("LibraryService == null");
			}
			
			// clean up
			libServ = null;
			context.ungetService(sr);
		} else {
			System.out.println("ServiceReference == null");
		}

		sr = null;

	}

	public void stop(BundleContext context) throws Exception {
		// TODO Auto-generated method stub

	}

}
